import { encapsulation, request } from '@/network/request' //encapsulation ,
import { getToken } from '@/network/bookManager.js'
/*
 *@functionName: 查询轮播图 与图书详情
 *@params1: 参数1
 *@description:
 *@author: chendi
 *@date: 2020-08-24 19:05:09
 *@version: V1.0.5
 */
export async function queryRotationChart(option) {
  let token = await getToken()
  return request({
    url: `/api/tcb/invokecloudfunction?&access_token=${token.access_token}&env=zhuma-mbnti&name=queryRotationChart`,
    method: `post`,
    data: JSON.stringify(option)
  })
}
/*
 *@functionName:  修改轮播图方法
 *@params1: 轮播图对象
 *@description:
 *@author: chendi
 *@date: 2020-08-25 11:02:00
 *@version: V1.0.5
 */
export function modifyRotationChart(option) {
  return encapsulation({
    url: `/api/tcb/databaseupdate`,
    method: `post`,
    data: {
      query: `db.collection('boxRotationChart')
      .where({
        _id:'${option._id}'
      })
      .update({
        data: {
          ${option.chartBookId ? `chartBookId:'${option.chartBookId}',` : ``}
          ${
            option.chartDescribe
              ? `chartDescribe:'${option.chartDescribe}',`
              : ``
          }
          ${
            option.chartStatus != undefined
              ? `chartStatus:${option.chartStatus},`
              : ``
          }
          ${option.chartUrl ? `chartUrl:'${option.chartUrl}'` : ``}
        }
      })
    `
    }
  })
}
/*
 *@functionName: 添加轮播图方法
 *@params1: 轮播图对象
 *@description:
 *@author: chendi
 *@date: 2020-08-26 09:14:18
 *@version: V1.0.5
*/
export function addRotationChart(option) {
  return encapsulation({
    url: `/api/tcb/databaseadd`,
    method: `post`,
    data: {
      query: `db.collection('boxRotationChart')
      .add({
        data: {
            chartBookId:'${option.chartBookId}',
            chartDescribe: '${option.chartDescribe}',
            chartStatus: ${option.chartStatus},
            chartUrl:'${option.chartUrl}'
          }
      })
    `
    }
  })
}

/*
 *@functionName: 真正删除 轮播图
 *@params1: 参数1
 *@description:
 *@author: chendi
 *@date: 2020-09-01 21:02:59
 *@version: V1.0.5
*/
export function removeRotationChartId(option) {
  return encapsulation({
    url: `/api/tcb/databasedelete`,
    method: 'post',
    data: {
      query: `db.collection('boxRotationChart')
      .where({
         _id:'${option}'
      }).remove()`
    }
  })
}